package com.shq.ex1;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;

public class ZhuCeActivity extends AppCompatActivity {
    private EditText nickName;
    private EditText pwd;
    private EditText pwd2;
    private Spinner spinner;
    private RadioGroup sex;
    private RadioButton radio;
    private ListView listView;
    private CheckBox checkBox;
    private Button reg = null;
    private int position = -1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhu_ce);

        nickName = (EditText)findViewById(R.id.editTextUserName);
        pwd = (EditText)findViewById(R.id.editTextPassWord);
        pwd2 = (EditText)findViewById(R.id.editTextPassWordC);
        spinner = (Spinner)findViewById(R.id.spinner);
        checkBox = (CheckBox)findViewById(R.id.checkBox);
        listView = (ListView)findViewById(R.id.listview00);
        sex = (RadioGroup)findViewById(R.id.sex);
        reg = (Button)findViewById(R.id.reg);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.care,android.R.layout.simple_spinner_item);
        listView.setAdapter(adapter);
        checkBox.setOnCheckedChangeListener(new checkBoxOnCheckedChangeListener());
        sex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
            public void onCheckedChanged(RadioGroup group,int checkedId){
                radio = (RadioButton)findViewById(checkedId);
            }
        });
        spinner.setOnItemSelectedListener(new spinnerOnItemSelectedListener());

        reg.setOnClickListener(new regOnClickListener());

    }

    class checkBoxOnCheckedChangeListener implements CompoundButton.OnCheckedChangeListener {
        @Override
        public void onCheckedChanged(CompoundButton buttonView,boolean isChecked){
            if(isChecked){
                reg.setVisibility(View.VISIBLE);
            }else{
                reg.setVisibility(View.INVISIBLE);
            }
        }
    }

    class spinnerOnItemSelectedListener implements AdapterView.OnItemSelectedListener{

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            position = arg2;
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }

    }

    class regOnClickListener implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            Log.i("您输入的用户名为：", nickName.getText().toString());
            Log.i("您输入的密码为：", pwd.getText().toString());
            Log.i("您输入的确认密码为：", pwd2.getText().toString());
            if(radio != null){
                Log.i("您输入的性别为：", radio.getText().toString());
            }else {
                Log.i("您输入的性别为：", "无");
            }
            Log.i("您选择的身份为：", spinner.getItemAtPosition(position).toString());
        }
    }

}
